home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.02 Feb 87 / MacApp Text Editor / UDemoText.p < prev   
Encoding:
Text File  |  1986-12-31  |  4.1 KB  |  176 lines  |  [TEXT/MPS ]

  1. {Copyright © 1986 by Apple Computer, Inc.  All Rights Reserved.}
  2.  
  3. UNIT UDemoText;
  4.  
  5. {This sample application demonstrates the breadth of alternatives available
  6.     when using the MacApp building-block "UTEView" for text-editing.}
  7.  
  8. INTERFACE
  9.  
  10. USES
  11.     {$LOAD MacIntf.LOAD}
  12.         MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
  13.     {$LOAD UMacApp.LOAD}
  14.         UObject, UList, UMacApp,
  15.     {$LOAD}
  16.  
  17.     UPrinting,
  18.  
  19.     UTEView;
  20.  
  21.  
  22. CONST
  23.  
  24.   {Command numbers}
  25.  
  26.     cWidthFrame     =    601;        {View-width-determination commands}
  27.     cWidthView        =    602;
  28.     cWidthOnePage    =    603;
  29.  
  30.     cHeightFrame    =    604;        {View-height-determination commands}
  31.     cHeightPages    =    605;
  32.     cHeightText     =    606;
  33.     cHeightConst    =    607;
  34.  
  35.     cJustLeft        =    608;        {Justification commands}
  36.     cJustCenter     =    609;
  37.     cJustRight        =    610;
  38.  
  39.  
  40.   {Other constants}
  41.  
  42.     kSignature        =  'SS04';     {application signature}
  43.     kFileType        =  'TEXT';     {file-type code for saved disk files -- uses
  44.                                     standard text files}
  45.     kWindowRsrcID    =    1004;     {Resource ID of the WIND resource used to
  46.                                     obtain the windows used by this app}
  47.  
  48.  
  49.  
  50. TYPE
  51.  
  52.     TextSpecs =   {Text specifications}
  53.         RECORD
  54.             theFontNumber:        INTEGER;
  55.             theFontSize:        INTEGER;
  56.             theStyle:            Style;
  57.             theJustification:    INTEGER;
  58.         END;
  59.     TextSpecsPtr = ^TextSpecs;
  60.     TextSpecsHdl = ^TextSpecsPtr;
  61.  
  62.  
  63.  
  64.     TDemoTextApplication = OBJECT(TApplication)
  65.  
  66.         PROCEDURE  TDemoTextApplication.IDemoTextApplication;
  67.             {Initialize the Application}
  68.  
  69.         FUNCTION  TDemoTextApplication.DoMakeDocument(itsCmdNumber: CmdNumber):
  70.                                                             TDocument; OVERRIDE;
  71.             {Launches a TTextDocument}
  72.  
  73. {$IFC qDebug}
  74.         PROCEDURE TDemoTextApplication.IdentifySoftware; OVERRIDE;
  75. {$ENDC}
  76.  
  77.         END;
  78.  
  79.  
  80.  
  81.     TTextDocument = OBJECT(TDocument)
  82.  
  83.         fText:            Handle;         {The text owned by the document}
  84.         fTEView:        TTEView;        {The view which displays the text}
  85.  
  86.         fTextSpecs:     TextSpecs;        {Specifies properties of the text}
  87.         fSpecsChanged:    BOOLEAN;        {Specifications have changed since last
  88.                                             time menus were set up}
  89.         fCurrFontMenu:    INTEGER;        {Currently selected font menu item}
  90.  
  91.  
  92.      {Initialization and freeing}
  93.  
  94.         PROCEDURE TTextDocument.ITextDocument;
  95.         PROCEDURE TTextDocument.Free; OVERRIDE;
  96.         PROCEDURE TTextDocument.DoInitialState; OVERRIDE;    
  97.         PROCEDURE TTextDocument.FreeData; OVERRIDE;
  98.  
  99.  
  100.      {Filing}
  101.  
  102.         PROCEDURE TTextDocument.DoNeedDiskSpace(VAR dataForkBytes, 
  103.                                              rsrcForkBytes: LONGINT); OVERRIDE;
  104.         PROCEDURE TTextDocument.DoRead(aRefNum: INTEGER; rsrcExists,
  105.                                             forPrinting: BOOLEAN); OVERRIDE;
  106.         PROCEDURE TTextDocument.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN);
  107.                                                                     OVERRIDE;
  108.  
  109.  
  110.      {Making views and windows}
  111.  
  112.         PROCEDURE TTextDocument.DoMakeViews(forPrinting: BOOLEAN); OVERRIDE;
  113.         PROCEDURE TTextDocument.DoMakeWindows; OVERRIDE;
  114.  
  115.  
  116.      {Command processing}
  117.  
  118.         FUNCTION  TTextDocument.DoMenuCommand(aCmdNumber: CmdNumber): TCommand;
  119.                                                                     OVERRIDE;
  120.         PROCEDURE TTextDocument.DoSetupMenus; OVERRIDE;
  121.  
  122.  
  123.      {Auxiliary routine}
  124.  
  125.         PROCEDURE TTextDocument.InstallTextSpecs(specs: TextSpecs);
  126.             {Installs the properties implied by values in 'specs' into the
  127.                 TextEdit record}
  128.  
  129.         PROCEDURE TTextDocument.ShowReverted; OVERRIDE;
  130.             {When the user reverts a document, this is called after reading
  131.              the old document and before displaying it.  Causes the reverted
  132.              font specs to be installed.}
  133.  
  134.         END;
  135.  
  136.  
  137.  
  138.     TTextCommand = OBJECT(TCommand)  {A Command which changes properties of text}
  139.  
  140.         fOldTextSpecs:    TextSpecs;        {Text specifications before command is
  141.                                             done -- used for UNDO}
  142.         fNewTextSpecs:    TextSpecs;        {Text specifications after command is
  143.                                             done -- used for DO/REDO}
  144.  
  145.         fTEView:        TTEView;        {The view to which the command applies}
  146.         fTextDocument:    TTextDocument;    {The corresponding text document}
  147.  
  148.  
  149.      {Initialization}
  150.  
  151.         PROCEDURE TTextCommand.ITextCommand(itsCmdNumber: CmdNumber;
  152.                                             itsTextDocument: TTextDocument;
  153.                                             itsTEView: TTEView;
  154.                                             itsFontNumber: INTEGER;
  155.                                             itsFontSize: INTEGER;
  156.                                             itsStyle: Style;
  157.                                             itsJustification: INTEGER);
  158.  
  159.  
  160.      {Command execution phases}
  161.  
  162.         PROCEDURE TTextCommand.DoIt; OVERRIDE;
  163.         PROCEDURE TTextCommand.UndoIt; OVERRIDE;
  164.         PROCEDURE TTextCommand.RedoIt; OVERRIDE;
  165.  
  166.         END;
  167.  
  168.  
  169.  
  170. IMPLEMENTATION
  171.  
  172. {$I UDemoText.inc1.p}
  173.  
  174. END.
  175.  
  176.